package com.yanqu.road.dao.impl.log;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.db.DbParameter;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.log.*;

import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author cwq
 * @Data 2022/3/30 11:24
 */
public class LogShuShanDaoImpl extends TempDao {

    public boolean addLogShuShanBuildUpList(List<LogShuShanBuildUp> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_shushan_build_up(activityId,userId,build,prestige,oldLv,newLv,consume,time) VALUES(?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuShanBuildUp data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getBuild()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getPrestige()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOldLv()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getNewLv()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getConsume()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public boolean addLogShuShanGetDiscipleList(List<LogShuShanGetDisciple> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_shushan_get_disciple(activityId,userId,level,id,name,quality,totalValue,propertiesInfoMap,isGet,time) VALUES(?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuShanGetDisciple data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLevel()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getName()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getQuality()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTotalValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSON.toJSONString(data.getPropertiesInfoMap())));
            para.put(i++, new DbParameter(Types.BOOLEAN, data.isGet()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogShuShanKickOutDiscipleList(List<LogShuShanKickOutDisciple> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_shushan_kick_out_disciple(activityId,userId,level,id,quality,totalValue,propertiesInfoMap,learnedSkillMap,curBuildId,curLiLianId,time) VALUES(?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuShanKickOutDisciple data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLevel()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getQuality()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTotalValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSON.toJSONString(data.getPropertiesInfoMap())));
            para.put(i++, new DbParameter(Types.VARCHAR, JSON.toJSONString(data.getLearnedSkillMap())));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCurBuildId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getCurLiLianId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }

    public boolean addLogShuShanReceiveLiLianRewardList(List<LogShuShanReceiveLiLianReward> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_shushan_receive_lilian_reward(activityId,userId,id,quality,totalValue,propertiesInfoMap,liLianId,receiveId,reward,time) VALUES(?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuShanReceiveLiLianReward data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getQuality()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTotalValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSON.toJSONString(data.getPropertiesInfoMap())));
            para.put(i++, new DbParameter(Types.INTEGER, data.getLiLianId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getReceiveId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
    public boolean addLogShuShanEventRecordList(List<LogShuShanEventRecord> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_shushan_event_record(activityId,userId,type,eventId,optionsId,reward,refreshTime,time) VALUES(?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuShanEventRecord data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getType()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getEventId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getOptionsId()));
            para.put(i++, new DbParameter(Types.VARCHAR, data.getReward()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getRefreshTime()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }


    public boolean addLogShuShanExerciseRecordList(List<LogShuShanExerciseRecord> list) {
        boolean result = false;
        getDb().setConnName(DbNameStrategy.getLogDb());
        String sql = "INSERT INTO t_l_activity_shushan_exercise_record(activityId,userId,id,skillId,totalTimes,goodExerciseTimes,isUpBuild,oldValue,oldPropertiesInfo,newValue,newPropertiesInfo,endTime,time) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?)";
        List<Map<Integer, DbParameter>> mapList = new ArrayList<>();
        for (LogShuShanExerciseRecord data : list) {
            Map<Integer, DbParameter> para = new HashMap<>();
            int i = 1;
            para.put(i++, new DbParameter(Types.BIGINT, data.getActivityId()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getUserId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getSkillId()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getTotalTimes()));
            para.put(i++, new DbParameter(Types.INTEGER, data.getGoodExerciseTimes()));
            para.put(i++, new DbParameter(Types.BOOLEAN, data.isUpBuild()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getOldValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSON.toJSONString(data.getOldPropertiesInfo())));
            para.put(i++, new DbParameter(Types.BIGINT, data.getNewValue()));
            para.put(i++, new DbParameter(Types.VARCHAR, JSON.toJSONString(data.getNewPropertiesInfo())));
            para.put(i++, new DbParameter(Types.BIGINT, data.getEndTime()));
            para.put(i++, new DbParameter(Types.BIGINT, data.getTime()));
            mapList.add(para);
        }
        if (getDb().executeBatchQuery(sql, mapList) > -1) {
            result = true;
        }
        return result;
    }
}
